#ifndef ASTARTHREAD_H
#define ASTARTHREAD_H

#include <QThread>
#include <queue>
#include "Node.h"

//When passed to priority_queue as the Compare parameter, this struct allows
//the priority_queue to sort by the Node's f value.
struct NodeComparator : public std::binary_function<Node*, Node*, bool>
{
    bool operator()(const Node *a, const Node *b) const
    {
        return a->getF() > b->getF();
    }
};

typedef std::priority_queue<Node*, std::vector<Node*>, NodeComparator> NodeQueue;

class AStarThread : public QThread
{
    Q_OBJECT

public:
    AStarThread(void);
    void setNodes(Node*, Node*, Node*);

protected:
    void run(void);

public slots:
    void pauseSearch(void);

signals:
    void exploredNewNode(Node*, int);
    void finished(bool);

private:
    int calculateFValue(const Node&) const;
    int calculateEuclidianDistance(const Node&, const Node&) const;

    Node* startNodePtr;
    Node* destinationNodePtr;
    Node* excludedNodePtr;
    NodeQueue openList;
    bool pause;
};

#endif // ASTARTHREAD_H
